#include <iostream>
#include "symath.h"
#include <vector>
#include "lagrange.h"
#include <cmath>

#ifndef __SY__DEBUG__
#define __SY__DEBUG__
#endif

using namespace std;
using namespace sy::interpolation;

float fun(float x)
{
    return 0.5*sy::math::pow(x,3) + 0.3*sy::math::pow(x,2) + 7*x + 9.0f;
}

float func(float x)
{
    return 0.5*std::pow(x,3) + 0.3*std::pow(x,2) + 7*x + 9.0f;
}

int main(int argc, char *argv[])
{
    // 插值点
    const int n = 3;
    float x[n+1] = {1, 2, 3, 4};
    float y[n+1] = {2, 4, 6, 8};

// 产生一些点进行插值
    for(int i = 0; i <=n ; ++i)
    {
        x[i] = (float)(i+1);
        y[i] = fun(x[i]);
    }

    lagrange* L = CreateLagrange(x, y, n);

#ifdef __SY__DEBUG__
    // 插值函数的显示
    cout << *L << endl;
#endif // __SY__DEBUG__

    float xi = 1.5f;
    float result = GetValue(L,xi);
    cout << "f(" << xi << ") = " << result << endl;
    cout << "fun(" << xi <<") = " << func(xi) << endl;
    DestoryLangrange(L);
    return 0;
}